Repository navigation
fix: keep the story on screen in the swipe viewer, load past Algolia's 1,000-result cap, and two smaller fixes - #288
Merged
Conversation
A direct link to /item/:id mounted the story viewer inside
MobileItemResolver. The first swipe writes { from: 'top' } to the URL
state, which the wrapper maps to its own SwipeStoryViewer, so React
replaced the resolver's viewer with a new one. The new viewer started
from the Top feed, so a linked story that isn't in it (an Ask HN post,
an older story) was gone when you swiped back, and you landed on the
wrong story.
The wrapper now looks up the item type itself and renders the same
keyed viewer element as the { from: 'top' } branch, so the first swipe
keeps the instance.
Algolia search returns at most 1,000 hits, so the comment fetch stopped there: a 2,530-comment thread showed 1,000. When the first page shows the cap, the comments now also come from the /items endpoint, which returns the whole tree in one request. It misses a few comments that search has (47 on that thread), so its comments are added to the search results rather than replacing them. If it fails, the search results are used as before. The loop also stops at the last page search reports instead of asking for one more empty page.
useItemWithComments revalidates a stale cached item by fetching its comments, and that fetch reads the item from Firebase too, but only its text was used. The cached title, points and comment count stayed up to 24 hours old and were written back as fresh, so the next visit kept them too. This shows on a reload, a bookmark, Back to a story, or a story opened before the feed's prefetch reached it. They now come from the fetched item. The type stays the local one, because Firebase calls Ask/Show posts 'story', and a fetched item without a title (a deleted story) changes nothing but the body, as before. The e2e Firebase mock now has its own copy of each story that only the Algolia mocks listed, with the same title and counts. It used to answer them with a generic "Item <id>", which the swipe panel now shows once the comments load.
therealsama
force-pushed
the
fix/verified-thread-and-swipe-bugs
branch
from
October 5, 2026 16:09
8f7b010 to
491b221
Compare
A feed opened from its cache refreshes in the background, and the refresh replaced every story. The swipe viewer starts it at mount, but on a slow connection it lands after the first swipes: the panel's index stayed the same while the story under it changed, with no input from the reader. useInfiniteStories now takes the ids the reader has reached (keepOnRevalidate), and a refresh keeps those stories, followed by the fresh ones that aren't already there. The swipe viewer reports them on each change, from the first story through the one on screen, so the story on screen stays even at index 0. The feed cache still gets the fresh page as fetched. Desktop passes nothing, so its refresh still replaces the whole list. The feed counts as fresh once the page arrives, rather than once it adds a story: with stories kept, every fetched one can already be there, and the swipe viewer calls loadMore for as long as the feed is marked as cached. The list is rebuilt from the kept stories at that point too, even with nothing new on the page. The desktop list caches everything it loaded, and the cached stories past the kept ones are no longer in seenIds, so the next page would show them a second time. The e2e swipe helper now waits up to 2 s for a swipe to finish before sending it again, up from 500 ms. On Mobile Safari under load some swipes finished later than that, and the retry then moved the reader a panel further than asked; the new refresh test failed about one run in ten because of it.
The domain and user lists page through Algolia's search_by_date, which returns at most 1,000 hits and caps nbPages to match. Their 'has more' check ended at that last page, so /from/github.com and the submissions of anyone with more than 1,000 stories stopped with no sign that more existed. Past the last page, the next request now starts over at page 0 with created_at_i at or before the oldest hit so far. Results are newest first, so that picks up where the list stopped; the boundary story comes back once and the existing dedup drops it.
index.html adds the swipe-mode class before React loads, for routes that will mount a swipe viewer. Its regex ended in an optional group with no end anchor, so it matched every '#/' route. Only UserProfile cleared the class again, so a phone that opened a 404, /item/abc, or an empty /from/ or /submitted/ directly kept the swipe viewer's body styles (overflow: clip, no scrollbar) on a page that has no viewer. The regex now lists the routes App.tsx gives a viewer: the feeds, a numeric /item/, and a non-empty /from/ or /submitted/.
therealsama
force-pushed
the
fix/verified-thread-and-swipe-bugs
branch
from
October 5, 2026 17:35
491b221 to
a5994ed
Compare
therealsama
enabled auto-merge
October 5, 2026 18:48
kplachkov
approved these changes
Oct 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes six bugs found in an audit. Three were reproduced in the browser against the unfixed code (the new e2e tests below), the two 1,000-result caps were confirmed against the live Algolia API, and the stale-metadata one came from reading the code. Each commit is one fix with its tests.
Mobile swipe viewer
/#/item/:iddirectly mounted the viewer insideMobileItemResolver. The first swipe writes{ from: 'top' }to the URL state, which the wrapper maps to its ownSwipeStoryViewer, so React replaced the resolver's viewer with a new one that started from the Top feed. A shared Ask HN post or an older story was gone when you swiped back, and you landed on a different story. The wrapper now resolves the item type itself and renders the same keyed element as the{ from: 'top' }branch, so the first swipe keeps the viewer.useInfiniteStoriesnow takes the ids the reader has reached (keepOnRevalidate), and a refresh keeps only those stories, followed by the fresh ones that aren't already there. The swipe viewer reports them from the first panel through the one on screen, so the story on screen stays even at index 0, and a linked story it moved to the front keeps only itself. The feed cache still gets the fresh page as fetched. The feed counts as fresh once the page arrives, rather than once it adds a story: with stories kept, every fetched one can already be there, and the swipe viewer callsloadMorefor as long as the feed is marked as cached. The list is rebuilt from the kept stories at that point too, even when the page brings nothing new. The desktop list caches every story it loaded, so a phone that browsed the list in landscape (the desktop layout) and then read in portrait had cached stories past the kept ones. They stayed in the list, but they were no longer in the set of seen ids, so the next page showed them a second time.index.htmladds theswipe-modeclass before React loads, but its route regex ended in an optional group with no end anchor, so it matched every#/route. OnlyUserProfilecleared it, so a phone that opened a 404,/#/item/abc, or an empty/#/from/directly gotoverflow: clipand no scrollbar on a page with no viewer. The regex now lists only the routesApp.tsxgives a viewer.Comments and story data
/itemsendpoint, which returns the whole tree in one request. The tree misses some comments that search has, so the two are merged rather than one replacing the other. If the tree request fails, the search results are used as before. On a 2,530-comment thread (38309611), search returned 1,000, the tree 2,450, and 47 were only in search. The paging loop also stops at the last page search reports instead of asking for the empty page after it.textwas kept. The cached title, points and comment count stayed up to 24 hours old and were written back as fresh. They now come from the fetched item. The type stays the local one, because Firebase calls Ask/Show postsstory, and a fetched item with no title (a deleted story) changes only the body, as before.Domain and user lists
search_by_date, which returns at most 1,000 hits and capsnbPagesto match. So/#/from/github.com(over 460,000 stories) and the submissions of anyone with more than 1,000 stories ended with no sign there was more. Past the last page, the next request now starts again at page 0 withcreated_at_iat or before the oldest hit so far. Results are newest first, so this continues where the list stopped; the boundary story comes back once and the existing dedup drops it.Testing
npm run typecheck,npm run lintandnpm run test:runpass on every commit, not just the tip (1091 tests, 19 new).npm run e2e(chromium, firefox, Mobile Safari, Mobile Chrome, retries off): 932 tests, 42 skipped. Two full runs passed 888 and 889. Each failure happened in one run only and passed when rerun: two Mobile Safari axe scans hit their 60 s timeout, and a Firefox home page stayed on its loading skeleton for 10 s before any story arrived from the mock.mobile-swipe.spec.ts).mobile-swipe.spec.ts).mobile-swipe.spec.ts).mobile-swipe.spec.ts).swipe-modeclass is set for/#/best,/#/item/12345,/#/from/github.com/rust-langand/#/submitted/pg, and not for/#/user/pg,/#/no-such-page,/#/item/abcor/#/from/(mobile-breakpoint.spec.ts).main's source for these fixes, the e2e tests that check a bug (the two swipe tests and the four "not set" routes) failed on all four browsers, 24/24. The four "set" routes pass onmaintoo, since the old regex matched everything. They stop the new regex from leaving out a viewer route. The paging test passes onmain, which never had that problem: it failed on all four browsers against this PR's first version, where a refresh that brought no new story left the feed marked as cached and the viewer kept requesting older days. The no-new-stories test failed on all four browsers against this PR's previous version, which didn't rebuild the list, and passed 40/40 with the fix.maintoo: the tree request failing, a thread under the cap making no tree request, a deleted story keeping its cached title, and a refresh with nothing kept replacing the list. One existing test changed: a restored Ask HN item now also takes its points from the fetch.Item <id>, which the swipe panel now shows once the comments load. This is part of the stale-metadata commit.mobile-swipe.spec.ts, one of them unchanged by this PR, rendered the desktop layout because the emulated(pointer: coarse) and (hover: none)query read false. It didn't come back in 90 repeated runs of that spec or in the next full run.Not changed / known limitations
parts. This was found in the same audit and is left for a separate change.maintoo and is fixed separately in fix: treat a feed refresh with no stories as failed #289, which touches the same lines inuseInfiniteStories.ts.UserProfilestill turnsswipe-modeoff on mount. Direct loads no longer need it, but it's kept as a safety net.created_at_i, the cursor can't move past that second, so the list ends there instead of repeating.